package com.my.elasticsearchspringdemo.contorller;

import com.my.elasticsearchspringdemo.dao.UserRepository;
import com.my.elasticsearchspringdemo.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Description
 * @Author Godzilla
 * @Date 2019/7/6
 * @Version V1.0.0
 * @Update 更新说明
 */
@RestController
@RequestMapping("es-user")
public class UsersController {

    @Autowired
    private UserRepository userRepository;

    /**
     * 添加
     * @return
     */
    @RequestMapping("add")
    public String add() {
        User user =new User();
        user.setBirthday("19880101");
        user.setHobby("1111");
        user.setId(123123132L);
        user.setName("asdfsdafsdfsdfsdf");
        userRepository.save(user);
        return "success";
    }

    /**
     * 删除
     * @return
     */
    @RequestMapping("delete")
    public String delete() {
        User user =new User();
        user.setId(123123132L);
        userRepository.delete(user);
        return "success";
    }

    /**
     * 局部更新
     * @return
     */
    @RequestMapping("update")
    public String update() {
        User user =userRepository.findById(123123132L).get();
        user.setName("11111234235435111");
        userRepository.save(user);
        return "success";
    }
    /**
     * 查询
     * @return
     */
    @RequestMapping("query")
    public User query() {
        return userRepository.findById(123123132L).get();
    }

}
